<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/style.css">
</head>
<body>
    <form class="layui-form scms-form" id="form" lay-filter="form"> 
    <div class="wrapper">
        <div class="panel layui-panel">
                <div class="layui-tab layui-tab-brief" lay-filter="tab">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本内容</li>
                        <li>其他</li>
                    </ul>
                    
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <input type="input" name="id" value="{$content.id|default=0}" style="display: none;">
                            <div class="layui-form-item">
                                <label class="layui-form-label required">所属栏目：</label>
                                <div class="layui-input-block">
                                    <select name="column_id" lay-verify="required">
                                        <option value="">所属栏目</option>
                                        {foreach $column as $v}
                                        <option value="{$v.id}"{$v.children||$v.type>0?' disabled':''}{:isset($content.column_id)&&$content.column_id==$v.id?' selected':''}>
                                            {:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $v.level)}{$v.name}
                                        </option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label required">标题：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <input type="text" name="title" value="{$content.title|default=''}" lay-verify="required" value="" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">缩略图：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <div class="layui-input-prefix" style="padding: 0; width: 355px;">
                                            <div class="layui-btn-group">
                                                <button type="button" class="layui-btn layui-btn-primary" id="pic_upload"><i class="layui-icon layui-icon-upload-drag"></i> 上传</button>
                                                <button type="button" class="layui-btn layui-btn-primary" id="pic_preview"><i class="layui-icon layui-icon-eye"></i> 预览</button>
                                                <button type="button" class="layui-btn layui-btn-primary" id="get_pic"><i class="layui-icon layui-icon-carousel"></i> 获取内容首张图片</button>
                                            </div>
                                        </div>
                                        <input type="text" name="pic" value="{$content.pic|default=''}" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">跳转链接：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <input type="text" name="url" value="{$content.url|default=''}" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">内容：</label>
                                <div class="layui-input-block">
                                    <script id="editor" type="text/plain" style="width: 100%;">{$content_data|default=''|raw}</script>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否发布：</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="publish" value="1" title="是"{:isset($content.publish)&&$content.publish==1?' checked':''}{:isset($content.publish)?'':' checked'}>
                                    <input type="radio" name="publish" value="0" title="否"{:isset($content.publish)&&$content.publish==0?' checked':''}>
                                    <!-- <select name="publish">
                                        <option value="1"{:isset($content.publish)&&$content.publish==1?' selected':''}>是</option>
                                        <option value="0"{:isset($content.publish)&&$content.publish==0?' selected':''}>否</option>
                                    </select> -->
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">置顶/推荐：</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="top" title="置顶" lay-skin="tag"{:isset($content.top)&&$content.top==1?' checked':''}>
                                    <input type="checkbox" name="recommend" title="推荐" lay-skin="tag"{:isset($content.recommend)&&$content.recommend==1?' checked':''}>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">作者：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <input type="text" name="author" value="{$content.author|default=''}" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">来源：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <input type="text" name="source" value="{$content.source|default=''}" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">点击数：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <input type="number" name="clicks" value="{$content.clicks|default=0}" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序：</label>
                                <div class="layui-input-block">
                                    <div class="layui-input-group" style="width: 100%;">
                                        <input type="number" name="sort" value="{$content.sort|default=0}" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">优化标题：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="seotitle" value="{$content.seotitle|default=''}" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">关键字：</label>
                                <div class="layui-input-block">
                                    <textarea name="keywords" class="layui-textarea">{$content.keywords|default=''}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">描述：</label>
                                <div class="layui-input-block">
                                    <textarea name="description" class="layui-textarea">{$content.description|default=''}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">更新日期：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="update_time" id="update_time" value="" autocomplete="off" class="layui-input" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" id="save" lay-filter="save" lay-submit>保存</button>
                                <a class="layui-btn layui-btn-primary" onclick="parent.layer.closeAll();">取消</i></a>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
    </div>
    </form>
</body>
</html>
<script src="/static/layui/layui.js"></script>
<script src="/static/ueditorplus/ueditor.config.js"></script>
<script src="/static/ueditorplus/ueditor.all.js"></script>
<script>
layui.use(function() {
    var $ = layui.jquery
        form = layui.form,
        laydate = layui.laydate,
        upload = layui.upload;

    laydate.render({elem: '#update_time', type: 'datetime', value: new Date(), isInitValue: true, fullPanel: true});

    form.on('submit(save)', function(obj) {
        var postData = obj.field;
        var loadIndex = layer.load();
        $.post("{:url('admin/content/contentsave')}", postData, function(res) {
            layer.close(loadIndex);
            if (res.code > 0) {
                layer.alert(res.msg, {icon: 2});
            } else {
                var iframe = parent.window.document.getElementById('iframe');
                if (iframe === null) {
                    layer.msg(res.msg, {time: 500}, function() {
                        location.reload();
                    });
                } else {
                    parent.layer.closeAll();
                    iframe.contentWindow.layui.table.reloadData('table');
                    parent.layer.msg(res.msg, {time: 500});
                }
            }
        });
        return false;
    });

    upload.render({
        elem: '#pic_upload',
        url: "{:url('admin/index/upload')}",
        accept: 'images',
        acceptMime: 'image/*',
        done: function(res) {
            if (res.code > 0) {
                layer.alert(res.msg, {icon: 2});
            } else {
                layer.msg(res.msg, {time: 500});
                $('input[name="pic"]').val(res.data.src);
            }
        }
    });

    $('#pic_preview').click(function() {
        layer.photos({ photos: { 'data': [{ 'src': $('input[name="pic"]').val() }]} });
    });
    
    $('#get_pic').click(function() {
        var content = UE.getEditor('editor').getContent();
        var img = content.match(/<img.*?\ssrc=['"](.*?)['"]/i);
        $('input[name="pic"]').val(img === null ? '' : img[1]);
    });

    UE.getEditor('editor', {
        serverUrl: "{:url('admin/editor/ueditorplus')}",
        imageConfig: { disableOnline: true },
        initialFrameHeight: $(window).height() - 520,
        catchRemoteImageEnable: false,
    });
});
</script>